package com.tencent.mm.opensdk.modelmsg;

import android.os.Bundle;
import android.util.Log;

import com.tencent.mm.opensdk.modelmsg.WXMediaMessage.IMediaObject;

import java.io.File;

public class WXAppExtendObject implements IMediaObject {
    private static final int CONTENT_LENGTH_LIMIT = 10485760;
    private static final int EXTINFO_LENGTH_LIMIT = 2048;
    private static final int PATH_LENGTH_LIMIT = 10240;
    private static final String TAG = "MicroMsg.SDK.WXAppExtendObject";
    public String extInfo;
    public byte[] fileData;
    public String filePath;

    public WXAppExtendObject() {

    }

    public WXAppExtendObject(String arg1, String arg2) {

        this.extInfo = arg1;
        this.filePath = arg2;
    }

    public WXAppExtendObject(String arg1, byte[] arg2) {

        this.extInfo = arg1;
        this.fileData = arg2;
    }

    public boolean checkArgs() {
        int v3 = 10485760;
        boolean v0 = false;
        if (this.extInfo == null || this.extInfo.length() == 0) {
            if (this.filePath != null && this.filePath.length() != 0) {
            } else if (this.fileData != null && this.fileData.length != 0) {

            } else {
                Log.e("MicroMsg.SDK.WXAppExtendObject", "checkArgs fail, all arguments is null");
                return v0;
            }
        } else {
        }
        if (this.extInfo != null && this.extInfo.length() > 2048) {
            Log.e("MicroMsg.SDK.WXAppExtendObject", "checkArgs fail, extInfo is invalid");
            return v0;
        }

        if (this.filePath != null && this.filePath.length() > 10240) {
            Log.e("MicroMsg.SDK.WXAppExtendObject", "checkArgs fail, filePath is invalid");
            return v0;
        }

        if (this.filePath != null && this.getFileSize(this.filePath) > v3) {
            Log.e("MicroMsg.SDK.WXAppExtendObject", "checkArgs fail, fileSize is too large");
            return v0;
        }

        if (this.fileData != null && this.fileData.length > v3) {
            Log.e("MicroMsg.SDK.WXAppExtendObject", "checkArgs fail, fileData is too large");
            return v0;
        }

        return true;
    }

    private int getFileSize(String arg4) {
        int v0 = 0;
        if (arg4 != null && arg4.length() != 0) {
            File v1 = new File(arg4);
            if (v1.exists()) {
                v0 = ((int) v1.length());
            }
        }

        return v0;
    }

    public void serialize(Bundle arg3) {
        arg3.putString("_wxappextendobject_extInfo", this.extInfo);
        arg3.putByteArray("_wxappextendobject_fileData", this.fileData);
        arg3.putString("_wxappextendobject_filePath", this.filePath);
    }

    public int type() {
        return 7;
    }

    public void unserialize(Bundle arg2) {
        this.extInfo = arg2.getString("_wxappextendobject_extInfo");
        this.fileData = arg2.getByteArray("_wxappextendobject_fileData");
        this.filePath = arg2.getString("_wxappextendobject_filePath");
    }
}

